package kotlincomtest

import org.junit.Test
import java.lang.ref.ReferenceQueue
import java.lang.ref.WeakReference

class TestReferenceQueue {

    @Test
    fun testGC() {
        val refQueue = ReferenceQueue<Any?>()

        var obj: Any? = Object()

        val weakReference = WeakReference(obj, refQueue)

        println("before GC:${weakReference.get()}")

        obj = null

        System.gc()

        println("after GC:${weakReference.get()}")

        try {
            Thread.sleep(2000)
        } catch (ex: Exception) {
            ex.printStackTrace()
        }
    }
}